/**
 * 
 * @author  phoenics@126.com
 * @version v.0.1
 * @date  2018年3月14日 下午2:24:51 
 * 
 */
package phoenics.upservice.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import phoenics.common.BaseData.Effective;

/**
 *
 */
@Entity
@Table(name = "user", uniqueConstraints = @UniqueConstraint(columnNames = { "mobile" }))
public class User {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(User.class);
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	private String mobile;
	private String password;

	@Enumerated(EnumType.ORDINAL)
	private Effective enable = Effective.TRUE;

	@Column(name = "create_time", insertable = false, updatable = false)
	private Date createTime;

	@Transient
	private Set<String> authorities = new HashSet<>();

	// bi-directional many-to-one association to Project
	@OneToMany(mappedBy = "user",fetch=FetchType.LAZY)
	private List<Project> projects;

	// bi-directional many-to-many association to Project
	@ManyToMany(mappedBy = "users",fetch=FetchType.LAZY)
	private List<Project> followProjects;

	// bi-directional one-to-one association to UserDetail
	//@OneToOne(fetch = FetchType.LAZY)
	@OneToOne(mappedBy = "user",fetch=FetchType.LAZY)
	//@JoinColumn(name = "id", referencedColumnName = "user_id")
	private UserDetail userDetail;

	// bi-directional many-to-one association to UserProject
	@OneToMany(mappedBy = "user",fetch=FetchType.LAZY)
	private List<UserProject> userProjects;

	public User() {
	}

	public User(String phone, String password) {
		this.mobile = phone;
		this.password = password;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setAuthorities(Set<String> authorities) {
		this.authorities = authorities;
	}

	public Set<String> getAuthorities() {
		return authorities;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Effective getEnable() {
		return enable;
	}

	public void setEnable(Effective enable) {
		this.enable = enable;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public List<Project> getProjects() {
		return this.projects;
	}

	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}

	public Project addProject(Project project) {
		getProjects().add(project);
		project.setUser(this);

		return project;
	}

	public Project removeProject(Project project) {
		getProjects().remove(project);
		project.setUser(null);

		return project;
	}

	public List<Project> getFollowProjects() {
		return this.followProjects;
	}

	public void setFollowProjects(List<Project> followProjects) {
		this.followProjects = followProjects;
	}

	public UserDetail getUserDetail() {
		return this.userDetail;
	}

	public void setUserDetail(UserDetail userDetail) {
		this.userDetail = userDetail;
	}

	public List<UserProject> getUserProjects() {
		return this.userProjects;
	}

	public void setUserProjects(List<UserProject> userProjects) {
		this.userProjects = userProjects;
	}

	public UserProject addUserProject(UserProject userProject) {
		getUserProjects().add(userProject);
		userProject.setUser(this);

		return userProject;
	}

	public UserProject removeUserProject(UserProject userProject) {
		getUserProjects().remove(userProject);
		userProject.setUser(null);

		return userProject;
	}

}
